<%@page import="br.com.Modelo.UsuarioCliente"%>
<%@page import="java.util.List"%>
<%@page import="br.com.Modelo.Produto"%>
<%@page import="br.com.Modelo.UsuarioComerciante"%>
<%@page import="br.com.Modelo.Pagina"%>
<%@page import="br.com.Modelo.Endereco"%>
<%@page import="br.com.Dao.UsuarioClienteDao"%>
<%@page import="br.com.Dao.UsuarioComercianteDao"%>
<%@page import="br.com.Dao.ProdutoDao"%>
<%@page import="br.com.Dao.PaginaDao"%>
<%@page import="br.com.Dao.EnderecoDao"%>
<%@page import="java.io.IOException"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin - Bootstrap Admin Template</title>

    <!-- Bootstrap Core CSS -->
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="../public/css/sb-admin.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="../public/css/plugins/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="../public/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    
    <link href="../bootstrap/css/bootstrapValidator.css" rel="stylesheet">

	<script type="text/javascript" src="../bootstrap/js/bootstrapValidator.js"></script>
    
    <style>
    .btn-primary {
	color: #ffffff;
	text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
	background-color: #229ac8;
	background-image: linear-gradient(to bottom, #23a1d1, #1f90bb);
	background-repeat: repeat-x;
	border-color: #1f90bb #1f90bb #145e7a;
}

.btn-primary:hover,.btn-primary:active,.btn-primary.active,.btn-primary.disabled,.btn-primary[disabled]
	{
	background-color: #1f90bb;
	background-position: 0 -15px;
}
    
    
    </style>
</head>

<body>



	<%
		///allow access only if session exists
	    
		String[] id = (String[]) session.getAttribute("user");
	    
		UsuarioCliente userCliente = null;
		UsuarioComerciante userComerciante = null;

		UsuarioComercianteDao dao = new UsuarioComercianteDao();
		if (id != null) {
			
			if (id[1].equals("1")) {


			} else {

		   userComerciante = dao.validaAutenticacaoUser(
		Long.parseLong(id[0]), Integer.parseInt(id[1]));
			}
		}
		String userName = null;
		String sessionID = null;
		
		if (userComerciante != null) {
			Pagina pagina = new Pagina();
			PaginaDao paginaDao= new PaginaDao();
			//out.println(userComerciante.getIdPagina());
			pagina = paginaDao.getPagina(userComerciante.getIdPagina());
			
			if(pagina != null){
		  //  pagina = new PaginaDao().getPagina(userComerciante.getIdPagina());
	%>


    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="">Painel Administrativo</a>
            </div>
            <!-- Top Menu Items -->
            <ul class="nav navbar-right top-nav">
                
                
         	<li class="dropdown"><a class="dropdown-toggle" role="button"
				data-toggle="dropdown" href="#"> <i
					class="glyphicon glyphicon-user"></i> <%=userComerciante.getLogin()%>
					<span class="caret"></span></a>
				<ul id="g-account-menu" class="dropdown-menu" role="menu">
					<li><a href="#">Meu Perfil</a></li>
					<li><a href="/plataforma_marketing/LogoutServlet"><i class="glyphicon glyphicon-lock"></i>
							Sair</a></li>
				</ul></li>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <ul class="nav navbar-nav side-nav">
                     <li class="co">
                        <a href="/plataforma_marketing"><img src="/plataforma_marketing/img/logo.png"></img> </a>
                    </li>

                    <li class="">
                        <a href="admin_loja.jsp"><i class="fa fa-fw fa-file"></i> Configurações Pagina</a>
                    </li>
                  
                    <li>
                    <a href="javascript:;" data-toggle="collapse" data-target="#demo"><i class="fa fa-fw fa-arrows-v"></i> Produto<i class="fa fa-fw fa-caret-down"></i></a>
                      
                        <ul id="demo" class="collapse">
                            <li>
                             <a href="cadastrar_produto.jsp"><i class="glyphicon glyphicon-plus"></i> Cadastrar Produto</a></li>
                            
                             <li>
                                <a href="editar_produto.jsp"><i class="glyphicon glyphicon-cog"></i> Editar Produto</a>
                            </li>
                         
                        </ul>
                        
                        
                    </li>
                    <li>
                        <a href="config_admin.jsp"><i class="glyphicon glyphicon-plus"></i> Configurações Admin</a>
                    </li>
                    
                    	<li id="ir"><a href="/plataforma_marketing/<%=pagina.getPagina()%>"><i class="glyphicon glyphicon-transfer"></i>
					  Ir para Pagina</a></li>
               
                
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid">

                <!-- Page Heading -->
                <div class="row">        
                   

                     <div class="panel panel-default">
        <div class="panel-heading">
          <div class="panel-title">
            <i class="glyphicon glyphicon-wrench pull-right"></i>
            <h4>Configurar comerciante </h4>
          </div>
        </div>
        <div class="panel-body">
        
        	        <%
				
				if(request.getParameter("check-cad")!= null){
			%>
	<div class="alert alert-danger">  
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Erro!</strong> <%=request.getParameter("check-cad") %>
   </div>
           <%} %>
           
           				
				<%if(request.getParameter("check-ok")!= null){%>
	<div class="alert alert-success">  
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>OK!</strong> <%=request.getParameter("check-ok") %>
   </div>
           <%} %>
          
   
					<form id="formadm" class="form-horizontal" action="/plataforma_marketing/admin/editar_comerciantes" method="post">
						<fieldset>


							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="login_empresa">Nome
									de Usuário</label>
								<div class="col-md-5">
									<input id="login_empresa" name="login_empresa" type="text"
										placeholder="login" class="form-control input-md" value="<%=userComerciante.getLogin()%>" >

								</div>
							</div>

							<!-- Password input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="senha_empresa">Senha</label>
								<div class="col-md-5">
									<input id="senha_empresa" name="senha_empresa" type="password"
										placeholder="" class="form-control input-md" value="<%=userComerciante.getSenha() %>">

								</div>
							</div>
						

							<hr class="prettyline">
						
							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="nome_empresa">Nome
									da Empresa</label>
								<div class="col-md-5">
									<input id="nome_empresa" name="nome_empresa" type="text"
										placeholder="" class="form-control input-md" value="<%=userComerciante.getNome() %>">

								</div>
							</div>

							<!-- Select Basic -->
							<div class="form-group">
								<label class="col-md-2 control-label" for="ramo_empresa">Ramo
									de Atividade</label>
								<div class="col-md-5">
									<select id="ramo_empresa" name="ramo_empresa"  
										class="form-control">
										<option value="1">Loja de Roupas</option>
										<option value="2">Sapataria</option>
										<option value="3">Móveis e Eletrodomésticos</option>
										<option value="4">Supermercado</option>
										<option value="5">Eletronicos</option>
									</select>
								</div>
							</div>

							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="cnpj">Cnpj</label>
								<div class="col-md-5">
									<input id="cnpj" name="cnpj" type="text" placeholder=""
										class="form-control input-md" value="<%=userComerciante.getCnpj() %>">

								</div>
							</div>

                                 <input type="hidden" name="id_comerciante" value="<%=userComerciante.getId()%>">
						
							<br />
							<!-- Button -->
							<div class="form-group" align="left">
								<label class="col-md-2 control-label" for="signin">&nbsp</label>

								<div class="col-md-5">
									<button id="signin" name="signin" type="submit" class="btn btn-success">Atualizar</button>
								</div>
							</div>

						</fieldset>
					</form>
				
          
        </div><!--/panel content-->
      </div><!--/panel-->
    

  
                </div>
                <!-- /.row -->

               

            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery Version 1.11.0 -->
    <script src="../public/js/jquery-1.11.0.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="../public/js/bootstrap.min.js"></script>

    <!-- Morris Charts JavaScript -->

<script type="text/javascript" src="../bootstrap/js/bootstrapValidator.js"></script>  
<script>
$(document).ready(function() {
$('#formadm').bootstrapValidator({
    //live: 'disabled',
    message: 'This value is not valid',
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {	        		          
    	login_empresa: {	               
            validators: {
                notEmpty: {
                    message: 'O nome de usuário é necessário e não pode ser vazio'
                },
                stringLength: {
                    min: 6,
                    max: 30,
                    message: 'O nome de usuário deve ter mais de 6 e menos de 30 caracteres'
                },
                regexp: {
                    regexp: /^[a-zA-Z0-9_\.]+$/,
                    message: 'O nome de usuário não pode consistir de pontos, virgulas ou espaços'
                }
               
            }
        },senha_empresa: {
            validators: {
                notEmpty: {
                    message: 'O nome de usuário é necessária e não pode ser vazio'
                },
                different: {
                    field: 'login_empresa',
                    message: 'A palavra-passe não pode ser o mesmo como nome de usuário'
                }
            }
        },
	cnpj:{
		validators:{
            notEmpty: {
                message: 'O cnpj não pode ser vazio'
            },
			regexp: {
            regexp: /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/,
            message: 'O cnpj informado não tem formato válido'
        }
	}
	}    
    }
	}); 	    

}); 	    


</script>   
    <%
		}}
	%>

</body>

</html>